#!/usr/bin/perl
#save_create.cgi
require './diskman-lib.pl';
&ReadParse();

my ($err_msg, $log_ev, $log_msg, $log_pri);

$err_msg="";
$log_ev="";

my $logivol = $in{'lvname'};
`echo $logivol > /root/logi`;
if($logivol =~ /^(\/dev\/sd\S)diskarray(\d)/){
   $lvdev = $1;
   $voldir="/usrvol/volume".$2;

}

#begin mkfs. Because mkfs is very time consumed, fork a child process

my $child_pid=fork;
if (!defined($child_pid)) {
        $log_ev = $text{'log_ev_mkfs_fork_err'};
        $log_msg= &text('log_msg_mkfs_fork_err', $volname);
        nas_syslog($text{'my_log_minor'}, 'naslog_warning', $log_ev, $log_msg);

        $err_msg = $text{'err_systemerror'};
        goto ERROR_OUT;
}

if ($child_pid) {

        open(MKFS_LOCK, ">".$config{'mkfs_lock_new'});
        print MKFS_LOCK $child_pid, "\n";
        close(MKFS_LOCK);
        &redirect("volstat.cgi");
}
else {
        #child process
        while(1) {
                if (-s $config{'mkfs_lock_new'}) {
                        last;
                }
                sleep(1);
        }
        exec './mkfsd.pl', $lvdev, $voldir;
}

ERROR_OUT:
&error_setup($text{'crt_err_title'});
&error($err_msg);


